<?php
class ControllerInscripciones extends Controller {
	var $error = array();
      
 
	function index() {
		$response =& $this->locator->get('response');
		$language =& $this->locator->get('language');
		$template =& $this->locator->get('template'); 
		$module   =& $this->locator->get('module');

		$language->load('controller/inscripciones.php');

		$template->set('title', $language->get('heading_title'));

		$template->set('content', $this->getList());

		$template->set($module->fetch());

		$response->set($template->fetch('layout.tpl'));
	}

/*	function insert() {
		$request  =& $this->locator->get('request');
		$response =& $this->locator->get('response');
		$database =& $this->locator->get('database');
		$url      =& $this->locator->get('url');
		$language =& $this->locator->get('language');
		$template =& $this->locator->get('template');
		$session  =& $this->locator->get('session');
		$module   =& $this->locator->get('module');
		$cache    =& $this->locator->get('cache');

		$language->load('controller/operaciones.php');

		$template->set('title', $language->get('heading_title'));

		if (($request->isPost()) && ($this->validateForm())) {
		$sql = "insert into operaciones set descripcion = '?', desdefecha ='?', hastafecha ='?'";
			$database->query($database->parse($sql, $request->get('descripcion', 'post'),$request->get('desdefecha', 'post'), $request->get('hastafecha', 'post')));

			$cache->delete('operaciones');

			$session->set('message', $language->get('text_message'));
			
			$response->redirect($url->ssl('operaciones'));
		}

		$template->set('content', $this->getForm());

		$template->set($module->fetch());

		$response->set($template->fetch('layout.tpl'));
	}
*/
	function update() {
		$request  =& $this->locator->get('request');
		$response =& $this->locator->get('response');
		$database =& $this->locator->get('database');
		$url      =& $this->locator->get('url');
		$language =& $this->locator->get('language');
		$template =& $this->locator->get('template');
		$session  =& $this->locator->get('session');
		$module   =& $this->locator->get('module');
		$cache    =& $this->locator->get('cache');

		$language->load('controller/inscripciones.php');

		$template->set('title', $language->get('heading_title'));

		if (($request->isPost()) && ($this->validateForm())) {
			$sql = "update operaciones set descripcion = '?', desdefecha ='?', hastafecha = '?' where opcion = '?'";
			$database->query($database->parse($sql, $request->get('descripcion', 'post'), $request->get('desdefecha', 'post'), $request->get('hastafecha', 'post'), $request->get('opcion', 'get')));

			$cache->delete('inscripciones');
			
			$session->set('message', $language->get('text_message'));
			
			$response->redirect($url->ssl('inscripciones'));
		}

		$template->set('content', $this->getForm());

		$template->set($module->fetch());

		$response->set($template->fetch('layout.tpl'));
	}
/*
	function delete() {
		$request  =& $this->locator->get('request');
		$response =& $this->locator->get('response');
		$database =& $this->locator->get('database');
		$url      =& $this->locator->get('url');
		$language =& $this->locator->get('language');
		$template =& $this->locator->get('template');
		$session  =& $this->locator->get('session');
		$module   =& $this->locator->get('module');
		$cache    =& $this->locator->get('cache');
 
		$language->load('controller/operaciones.php');

		$template->set('title', $language->get('heading_title'));

		if (($request->get('opcion'))) {
			$database->query("delete from Operaciones where opcion = '" . (int)$request->get('opcion','get') . "'");
			
			$database->query("delete from materiasoperacion where op_codigo = '" . (int)$request->get('opcion','get') . "'");

			$cache->delete('operaciones');
			
			$session->set('message', $language->get('text_message'));
			
			$response->redirect($url->ssl('operaciones'));
		}

		$template->set('content', $this->getList());

		$template->set($module->fetch());

		$response->set($template->fetch('layout.tpl'));
	}
 
 */

	function getList() {
		$request  =& $this->locator->get('request');
		$database =& $this->locator->get('database');
		$config   =& $this->locator->get('config');
		$url      =& $this->locator->get('url');
		$language =& $this->locator->get('language');
		$session  =& $this->locator->get('session');

		
		$cols = array();

		$cols[] = array(
			'name'  => $language->get('column_id'),
			'sort'  => 'opcion',
			'align' => 'left'
		);
                
                
                $cols[] = array(
			'name'  => $language->get('column_cod_operacion'),
			'sort'  => 'opcion',
			'align' => 'left'
		);

		$cols[] = array(
			'name'  => $language->get('column_descripcion'),
			'sort'  => 'descripcion',
			'align' => 'left'
		);

		
		$cols[] = array(
			'name'  => $language->get('column_desdefecha'),
			'sort'  => 'desdefecha',
			'align' => 'left'
		);
		
		$cols[] = array(
			'name'  => $language->get('column_hastafecha'),
			'sort'  => 'hastafecha',
			'align' => 'left'
		);
		$cols[] = array(
			'name'  => $language->get('column_carrera'),
			'sort'  => 'cod_carrera',
			'align' => 'left'
		);
		$cols[] = array(
			'name'  => $language->get('column_materia'),
			'sort'  => 'cod_materia',
			'align' => 'left'
		);
		$cols[] = array(
			'name'  => $language->get('column_comision'),
			'sort'  => 'cod_comision',
			'align' => 'left'
		);

    	$cols[] = array(
      		'name'  => $language->get('column_action'),
      		'align' => 'right'
    	);
		
		if (!$session->get('operaciones.search')) {
			$sql = "select mp.idmo,opcion, op.descripcion as operacion, desdefecha, hastafecha,op_codigo,mp.cod_carrera,mp.cod_materia,mp.cod_comision,car.cod_carrera,car.descripcion as carrera,mat.cod_materia,mat.descripcion as materia,com.cod_comision,com.descripcion as comision
				from operaciones as op 
				inner join materiasoperacion as mp 
				on op.opcion=mp.op_codigo 
				inner join carreras as car 
				on mp.cod_carrera=car.cod_carrera
				inner join materias as mat
				on mp.cod_materia=mat.cod_materia
				inner join comisiones as com
				on mp.cod_comision=com.cod_comision";
		} else {
			$sql = "select mp.idmo, opcion, op.descripcion as operacion, desdefecha, hastafecha,op_codigo,mp.cod_carrera,mp.cod_materia,mp.cod_comision,car.cod_carrera,car.descripcion as carrera,mat.cod_materia,mat.descripcion as materia,com.cod_comision,com.descripcion as comision
				from operaciones as op 
				inner join materiasoperacion as mp 
				on op.opcion=mp.op_codigo 
				inner join carreras as car 
				on mp.cod_carrera=car.cod_carrera
				inner join materias as mat
				on mp.cod_materia=mat.cod_materia
				inner join comisiones as com
				on mp.cod_comision=com.cod_comision where operacion like '?'";
		}

		$sort = array(
			'descripcion',
		);

		if (in_array($session->get('operaciones.sort'), $sort)) {
			$sql .= " order by " . $session->get('operaciones.sort') . " " . (($session->get('operaciones.order') == 'desc') ? 'desc' : 'asc');
		} else {
			$sql .= " order by opcion asc";
		}

		$results = $database->getRows($database->splitQuery($database->parse($sql, '%' . $session->get('operaciones.search') . '%'), $session->get('operaciones.page'), $config->get('config_max_rows')));

		$rows = array();

		foreach ($results as $result) {
			$cell = array();

		
                        	$cell[] = array(
				'value'   => $result['idmo'],
				'align'   => 'left',
				'default' => 0
			);
                        
                        
                        
                        $cell[] = array(
				'value'   => $result['opcion'],
				'align'   => 'center',
				'default' => 0
			);

			$cell[] = array(
				'value'   => $result['operacion'],
				'align'   => 'left',
				'default' => 0
			);

		

			$cell[] = array(
				'value'   => $result['desdefecha'],
				'align'   => 'left',
				'default' => 0
			);

			$cell[] = array(
				'value'   => $result['hastafecha'],
				'align'   => 'left',
				'default' => 0
			);
			$cell[] = array(
				'value'   => $result['carrera'],
				'align'   => 'left',
				'default' => 0
			);
			$cell[] = array(
				'value'   => $result['materia'],
				'align'   => 'left',
				'default' => 0
			);
			$cell[] = array(
				'value'   => $result['comision'],
				'align'   => 'left',
				'default' => 0
			);

			$action = array();
      		
			$action[] = array(
        		'icon' => 'update.png',
				'text' => $language->get('button_update'),
				'href' => $url->ssl('inscripciones', 'update', array('opcion' => $result['opcion']))
      		);
						
			
		

      		$cell[] = array(
        		'action' => $action,
        		'align'  => 'right'
      		);
			
			$rows[] = array('cell' => $cell);
		}

		$view = $this->locator->create('template');

		$view->set('heading_title', $language->get('heading_title'));
		$view->set('heading_description', $language->get('heading_description'));

		$view->set('text_default', $language->get('text_default'));
		$view->set('text_results', $language->get('text_results', $database->getFrom(), $database->getTo(), $database->getTotal()));

		$view->set('entry_page', $language->get('entry_page'));
		$view->set('entry_search', $language->get('entry_search'));
		$view->set('button_search', $language->get('button_search'));

		$view->set('button_list', $language->get('button_list'));
		$view->set('button_exportar', $language->get('button_exportar'));

		$view->set('error', @$this->error['message']);

		$view->set('message', $session->get('message'));
		
		$session->delete('message');
		
		$view->set('action', $url->ssl('inscripciones', 'page'));

		$view->set('search', $session->get('inscripciones.search'));
		$view->set('sort', $session->get('inscripciones.sort'));
		$view->set('order', $session->get('inscripciones.order'));
		$view->set('page', $session->get('inscripciones.page'));
 
                $view->set('export', $url->ssl('inscripciones','exportar'));

		$view->set('titulo_ventana', '::. Exportar Inscripciones');
		$page_data = array();

		for ($i = 1; $i <= $database->getPages(); $i++) {
			$page_data[] = array(
				'text'  => $language->get('text_pages', $i, $database->getPages()),
				'value' => $i
			);
		}

		$view->set('pages', $page_data);
                
		$view->set('cols', $cols);
		$view->set('rows', $rows);

		$view->set('list', $url->ssl('inscripciones'));

		$view->set('inscrip', $url->ssl('inscripciones', 'inscrip'));

		$page_data = array();
//HASTA 
		for ($i = 1; $i <= $database->getPages(); $i++) {
			$page_data[] = array(
				'text'  => $language->get('text_pages', $i, $database->getPages()),
				'value' => $i
			);
		}

		$view->set('pages', $page_data);

		return $view->fetch('content/list.tpl');
	}

        function exportar()
	{
		$request  =& $this->locator->get('request');
		$database =& $this->locator->get('database');
		$session  =& $this->locator->get('session');
		set_time_limit(0);
		
		$filtro = 'Filtro:';
		
		$htmlTable="<table border=0 width=180> 
			<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
                        <tr><td colspan=6 align=center style=bold size=14>M.C.G.A.</td></tr>
			<tr><td colspan=6 align=center style=bold size=12>Ciclo lectivo 2011</td></tr>
			<tr><td colspan=6 align=center style=bold size=10>Listado de Inscripciones</td></tr>
			<tr><td colspan=6 align=center></td></tr>
			<tr></tr>";

		if (!$session->get('inscripciones.id_ins'))
		{
			$sql = "SELECT  id_ins,
                                        ins.idmo,
                                        alumno,
                                        mato.idmo as matoIdmo,
                                        op_codigo,
                                        mato.cod_carrera AS idCa,
                                        mato.cod_materia AS idMa,
                                        mato.cod_comision AS idCo,
                                        opcion,
                                        op.descripcion AS descOp,
                                        desdefecha,
                                        hastafecha,
                                        ca.cod_carrera,
                                        ca.descripcion AS descCa,
                                        ma.cod_materia,
                                        ma.descripcion AS descMa,
                                        co.cod_comision,
                                        co.descripcion AS descCo,
                                        nroLegajo,
                                        apellido,
                                        nombre
                                FROM    inscripciones AS INS
                                        INNER JOIN materiasoperacion AS mato ON ins.idmo=mato.idmo
                                        INNER JOIN operaciones AS op ON op_codigo=opcion
                                        INNER JOIN carreras AS ca ON mato.cod_carrera=ca.cod_carrera
                                        INNER JOIN materias AS ma ON mato.cod_materia=ma.cod_materia
                                        INNER JOIN comisiones AS co ON mato.cod_comision=co.cod_comision
                                        INNER JOIN alumnos ON  alumno=nroLegajo";
		}
		else
		{
			$sql = "select cod_comision, descripcion from comisiones ";
		} //where cod_comision like '%" . $session->get('comisiones.cod_comision') . "%' or descripcion like '%" . $session->get('comisiones.cod_comision') . "%'
		

		$sql .= " order by id_ins asc";
				
		$reporte = $database->getRows($sql);

		foreach ($reporte as $estu)
		{
			
			$htmlTable .= 	"<tr><td colspan=6>__________________________________________________________________________</td></tr>
							<tr>
								<td align=left size=9>Nombre y Apellido: </td>
								<td align=left size=9>" . utf8_decode($estu['nombre']) . " " . utf8_decode($estu['apellido']) . "</td>
							</tr>
                                                        <tr>
								<td align=left size=9>Carrera: </td>
								<td align=left size=9>" . utf8_decode($estu['descCa']) . "</td>
							</tr>
							<tr>
								<td align=left size=9>Materia: </td>
								<td align=left size=9>" . utf8_decode($estu['descMa']) . "</td>
							</tr>
                                                        <tr>
								<td align=left size=9>Comision: </td>
								<td align=left size=9>" . utf8_decode($estu['descCo']) . "</td>
							</tr>
                                                        <tr>
								<td align=left size=9>Fecha Inicio: </td>
								<td align=left size=9>" . utf8_decode($estu['desdefecha']) . "</td>
							</tr>
                                                        <tr>
								<td align=left size=9>Fecha Cierre: </td>
								<td align=left size=9>" . utf8_decode($estu['hastafecha']) . "</td>
							</tr>";				
		}
			 
		$htmlTable .= "</table>";

	define('FPDF_FONTPATH','font/');
	require('javascript/pdf/pdftable.inc.php');
	//ob_end_clean();
	
	$p = new PDFTable();
	$p->AddPage();
	$p->setfont('times','',6);
	$p->htmltable($htmlTable);
	$p->output('','I');
	
	}
        
	function getForm() {
		$request  =& $this->locator->get('request');
		$database =& $this->locator->get('database');
		$url      =& $this->locator->get('url');
		$language =& $this->locator->get('language');
		$session  =& $this->locator->get('session');
		$view = $this->locator->create('template');

		$view->set('heading_title', $language->get('heading_title'));
		$view->set('heading_description', $language->get('heading_description'));

		$view->set('entry_cod_operacion', $language->get('entry_cod_operacion'));
		$view->set('entry_descripcion', $language->get('entry_descripcion'));
		//$view->set('entry_pagina', $language->get('entry_pagina'));
		$view->set('entry_desdefecha', $language->get('entry_desdefecha'));
		$view->set('entry_hastafecha', $language->get('entry_hastafecha'));
		//$view->set('entry_anio_aca', $language->get('entry_anio_aca'));
		//$view->set('entry_turexa', $language->get('entry_turexa'));
		
		$view->set('button_save', $language->get('button_save'));
		$view->set('button_cancel', $language->get('button_cancel'));

		$view->set('error', @$this->error['message']);
		$view->set('error_name', @$this->error['name']);
		$view->set('error_descripcion', @$this->error['descripcion']);
		//$view->set('error_pagina', @$this->error['pagina']);
		$view->set('error_desdefecha', @$this->error['desdefecha']);
		$view->set('error_hastafecha', @$this->error['hastafecha']);
		//$view->set('error_anio_aca', @$this->error['anio_aca']);
		//$view->set('error_turexa', @$this->error['turexa']);
		
		$view->set('tab_general', $language->get('tab_general'));
		$view->set('tab_materias', $language->get('tab_materias'));

		$view->set('action', $url->ssl('inscripciones', $request->get('action'), array('opcion' => $request->get('opcion'))));
 
		$view->set('cancel', $url->ssl('inscripciones'));

		if (($request->get('opcion')) && (!$request->isPost())) {
			$consulta = "select distinct * from operaciones where opcion = " . (int)$request->get('opcion');
			$inscripciones_info = $database->getRow($consulta);
		}

		if ($request->has('opcion', 'post')) {
			$view->set('opcion', $request->get('opcion', 'post'));
		} else {
			$view->set('opcion', @$inscripciones_info['opcion']);
		}

		if ($request->has('descripcion', 'post')) {
			$view->set('descripcion', $request->get('descripcion', 'post'));
		} else {
			$view->set('descripcion', @$inscripciones_info['descripcion']);
		}
		

		if ($request->has('desdefecha', 'post')) {
			$view->set('desdefecha', $request->get('desdefecha', 'post'));
		} else {
			$view->set('desdefecha', @$inscripciones_info['desdefecha']);
		}

		if ($request->has('hastafecha', 'post')) {
			$view->set('hastafecha', $request->get('hastafecha', 'post'));
		} else {
			$view->set('hastafecha', @$inscripciones_info['hastafecha']);
		}

             //   $legaj = $request->get('nroLegajo', 'get');   aca tendriamos que guardar al nroLegajo
             $op_codigo = $request->get('op_codigo', 'get');
               
$view->set('sel_materias', $database->getRows("Select mo.cod_materia,m.descripcion from
                materiasoperacion mo inner join 
                materias m on mo.cod_materia=m.cod_materia

"));
		
//  where op_codigo = '" . (int)$op_codigo . "'

		return $view->fetch('content/inscripciones.tpl');
	}

	function validateForm() {
		$request  =& $this->locator->get('request');
		$user     =& $this->locator->get('user');
		$language =& $this->locator->get('language');

	//	if (!$user->hasPermission('modify', 'operaciones')) {
	//		$this->error['message'] = $language->get('error_permission');
	//	}

		if ((strlen($request->get('descripcion', 'post')) == 0)) {
			$this->error['descripcion'] = $language->get('error_descripcion');
		}

		if ((strlen($request->get('desdefecha', 'post')) == 0)) {
			$this->error['desdefecha'] = $language->get('error_desdefecha');
		}

		if ((strlen($request->get('hastafecha', 'post')) == 0)) {
			$this->error['hastafecha'] = $language->get('error_hastafecha');
		}

		if (!$this->error) {
			return TRUE;
		} else {
			return FALSE;
		}
	}

	

	function page() {
		$request  =& $this->locator->get('request');
		$response =& $this->locator->get('response');
		$url      =& $this->locator->get('url');
		$session  =& $this->locator->get('session');

		if ($request->has('search', 'post')) {
			$session->set('inscripciones.search', $request->get('search', 'post'));
		}

		if (($request->has('page', 'post')) || ($request->has('search', 'post'))) {
			$session->set('inscripciones.page', $request->get('page', 'post'));
		}

		if ($request->has('sort', 'post')) {
			$session->set('inscripciones.order', (($session->get('inscripciones.sort') == $request->get('sort', 'post')) && ($session->get('inscripciones.order') == 'asc')) ? 'desc' : 'asc');
		}

		if ($request->has('sort', 'post')) {
			$session->set('inscripciones.sort', $request->get('sort', 'post'));
		}

		$response->redirect($url->ssl('inscripciones'));
	}
	
	function getMO()
	{
		$request  =& $this->locator->get('request');
		$database =& $this->locator->get('database');
		$config   =& $this->locator->get('config');
		$url      =& $this->locator->get('url');
		$language =& $this->locator->get('language');
		$response =& $this->locator->get('response');
			
		$language->load('controller/inscripciones.php');
			
		$view = $this->locator->create('template');
		
		$op_codigo = $request->get('op_codigo', 'get');
		
		//$materias = $database->getRows("select mo.idmo, mo.op_codigo, mo.cod_carrera, mo.cod_materia, mo.cod_comision from materiasoperacion mo where op_codigo = '" . (int)$op_codigo . "' order by mo.op_codigo asc");
		
		//$carreras = $database->getRows("select mo.op_codigo, mo.cod_carrera, mo.cod_materia, mo.cod_comision from materiasoperacion mo");
		
                $materias = $database->getRows("SELECT  mo.idmo,
                                                        mo.op_codigo,
                                                        mo.cod_carrera,
                                                        mo.cod_materia,
                                                        mo.cod_comision,
                                                        ca.cod_carrera,
                                                        ca.descripcion as carr,
                                                        ma.cod_materia,
                                                        ma.descripcion as matt,
                                                        co.cod_comision,
                                                        co.descripcion as comm
                                                FROM    materiasoperacion mo INNER JOIN
                                                        carreras ca ON mo.cod_carrera = ca.cod_carrera INNER JOIN
                                                        materias ma ON mo.cod_materia = ma.cod_materia INNER JOIN
                                                        comisiones co ON mo.cod_comision = co.cod_comision
                                                WHERE   op_codigo = '" . (int)$op_codigo . "'
                                                ORDER BY mo.op_codigo asc");
		
		$filas = "<tr>" .
					"<th>CODIGO</th>" .
					"<th>CARRERA</th>" .
					"<th>MATERIA</th>" .
					"<th>COMISION</th>" .
					"<th>ELIMINAR</th>" .
				"</tr>";
		
		foreach ($materias as $materia)
		{
			
			$datos_materia = $materia['idmo'];

			$deleteMO ="<img src='template/default/image/delete.png' class='png' onclick='clickDelete(" . $datos_materia . ");'/>";
						
			$filas .= "<tr id='materia_" .  $materia['op_codigo'] . $materia['cod_carrera']. $materia['cod_materia'] . $materia['cod_comision'] . "'>" .
						"<td align='center'>" . $materia['op_codigo'] . "</td>" .
						"<td align='center'>" . $materia['carr'] . "</td>" .
						"<td align='center'>" . $materia['matt'] . "</td>" .
						"<td align='center'>" . $materia['comm'] . "</td>" .
						"<td align='center'>" . $deleteMO . "</td>" .
					  "</tr>";			
		}
		
		echo $filas;
	}
	
	function deleteMO()
	{
		$request  =& $this->locator->get('request');
		$database =& $this->locator->get('database');
		$config   =& $this->locator->get('config');
		$url      =& $this->locator->get('url');
		$language =& $this->locator->get('language');
		$response =& $this->locator->get('response');
			
		$language->load('controller/inscripciones.php');
			
		$view = $this->locator->create('template');
		
		$codigo = $request->get('idmo', 'get');
		
		$database->query("delete from materiasoperacion where idmo ='" . (int)$codigo . "'");
		
	}	

	/*	function busca_materias()
		{
			$request  =& $this->locator->get('request');
			$database =& $this->locator->get('database');
			$config   =& $this->locator->get('config');
			$url      =& $this->locator->get('url');
			$response =& $this->locator->get('response');
			
			$view = $this->locator->create('template');
			
			$codoper =  $request->get('op_codigo', 'get');
			
			//$sqlBUSCA = "SELECT DISTINCT cod_materia FROM Materias WHERE cod_carrera ='" .$miCar . "'";
			$sqlBUSCA = "SELECT DISTINCT cod_materia FROM materiasoperacion WHERE op_codigo ='" .$codoper . "'";
			$BUSCA= $database->getRows($sqlBUSCA);
			
 			$optITEM ="<option value='-1' selected>--Seleccione--</option>"; 

  			foreach ($BUSCA as $F)
			{
				$optITEM .="<option value=" . $F['cod_materia'] . ">" . $F['descripcion'] . "</option>";
			} 
 			
			echo $optITEM;
		}
*/
		function busca_comisiones()
		{
			$request  =& $this->locator->get('request');
			$database =& $this->locator->get('database');
			$config   =& $this->locator->get('config');
			$url      =& $this->locator->get('url');
			$response =& $this->locator->get('response');
			
			$view = $this->locator->create('template');
			
			//$miCarr =  $request->get('ccar', 'get');
			$miMate =  $request->get('cmat', 'get');
			
			
			//$sqlBUSCA = "SELECT DISTINCT cod_comision, descripcion FROM Comision WHERE cod_materia ='" . $miMate . "'";
			$sqlBUSCA = "SELECT DISTINCT cod_comision, descripcion FROM comisiones WHERE cod_materia ='" . $miMate . "'";
			//$sqlBUSCA = "SELECT DISTINCT cod_comision, descripcion FROM Comisiones";

			$BUSCA= $database->getRows($sqlBUSCA);
			
 			$optITEM ="<option value='-1' selected>--Seleccione--</option>";
			//$optITEM .="<option value='0'>0 - Inscripci&oacute;n a examenes de alumnos regulares --</option>"; 
			
					foreach ($BUSCA as $F)
			{
				$optITEM .="<option value=" . $F['cod_comision'] . ">" . $F['cod_comision'] . ' - ' . $F['descripcion'] . "</option>";
			} 
 			
			echo $optITEM;
		}

		
			
		function addComision()
		{
			$request  =& $this->locator->get('request');
			$database =& $this->locator->get('database');
			$config   =& $this->locator->get('config');
			$url      =& $this->locator->get('url');
			$response =& $this->locator->get('response');
			
			$view = $this->locator->create('template');
			$codmate =  $request->get('cmate', 'get');
			$codope =  $request->get('op_codigo', 'get');
			$codcarr =  $request->get('ccar', 'get');
			$codcom =  $request->get('comisio', 'get');
                        $id =  $request->get('id', 'get');
                        
			//$sqlNIVEL = "select CNIVE from Comision where CMATE ='" . $miMate . "' and CPLAN = '" . $miPlan . "' and COMISIO = '" . $miComisio . "'";
			//$nivel = $database->getRow($sqlNIVEL);
			//$miNivel = $nivel['CNIVE'];
			
				$sqlBUSCA = "SELECT count(*) as total FROM materiasoperacion WHERE op_codigo ='" . $codope . "' and cod_carrera = '" .$codcarr . "' and cod_materia ='" .$codmate . "' and cod_comision ='" . $codcom . "' ";

			$BUSCA= $database->getRow($sqlBUSCA);
			
			if ($BUSCA['total'] == 0)
			{
                                $sql = "insert into materiasoperacion set op_codigo = '?', cod_carrera ='?', cod_materia ='?', cod_comision ='?'";
                                    $database->query($database->parse($sql,$codope,$codcarr,$codmate,$codcom));
				
                                    $addComision = 'OK';
			}
			else
			{
				$addComision = 'NO';
			}
			
			echo $addComision;
		}

}
?>